﻿<%@ Page Language="C#" AutoEventWireup="true" Culture="en-GB" CodeFile="CreditNoteEdit.aspx.cs" Inherits="Main_ServiceInvoice_CreditNoteEdit" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="AjaxControl" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Credit Note (Service Invoice)</title>
    <link href="../../Styles/accounts.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        function isNumberKey(control_id, evt) {
            var charCode = (evt.which) ? evt.which : event.keyCode
            if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode < 45 || charCode > 47))
                return false;

            if (charCode == 46) {
                var dotcount = document.getElementById(control_id).value.split('.').length - 1;
                if (dotcount >= 1) {
                    return false;
                }
            }
            return true;
        }
        function EnabledTabKey(id, e) {
            var keycode;
            if (window.event) {
                keycode = window.event.keyCode;
            }
            else if (e) {
                keycode = e.which;
            }
            else {
                return true;
            }

            if (keycode == 9) {
                // if is the tab key                
                return true;
            }
            else {
                return false;
            }
        }
        function GetLastNumber(sText) {
            var Char;
            var lastRow = 0;
            for (i = 0; i < sText.length; i++) {
                Char = sText.charAt(i);
                if (!isNaN(parseFloat(Char))) {
                    lastRow = sText.toString().substr(i);
                    break;
                }
            }
            return lastRow;
        }
        function ValidateAddMoreMain() {
            var flag = true;
            var lastNo = document.getElementById("hidRowCountMain").value;
            for (var i = 1; i <= lastNo; i++) {
                if (document.getElementById("ddlInvoiceParticular" + i).value == '0') {
                    alert('Specify Particulars');
                    flag = false;
                    document.getElementById("ddlInvoiceParticular" + i).focus();
                    break;
                }
                else if (document.getElementById("ddlServices" + i).value == '0') {
                    alert('Specify Services');
                    flag = false;
                    document.getElementById("ddlServices" + i).focus();
                    break;
                }
                else if (document.getElementById("txtTotalAmount" + i).value == '' || document.getElementById("txtTotalAmount" + i).value == '0.00') {
                    alert('Specify credit note amount');
                    flag = false;
                    document.getElementById("txtTotalAmount" + i).focus();
                    break;
                }
            }
            return flag;
        }
        function SetAmount(id) {
            var lastNo = GetLastNumber(id.toString());
            var radioList = document.getElementById("rbtCreditNoteType");
            var Inputs = radioList.getElementsByTagName("input");
            var ddlServices = document.getElementById("ddlServices" + lastNo);
            var ActualValue = document.getElementById(id).value;
            var hidTotalAmt = document.getElementById("hidTotalAmout" + lastNo).value;
            var SelectedValue; 
            for (var i = 0; i < Inputs.length; i++) {
                if (Inputs[i].type == "radio") {
                    if (Inputs[i].checked) {
                        SelectedValue = Inputs[i].value;
                        break;
                    }
                }
            }            
            if (ActualValue == '') {
                ActualValue = '0';
            }
            if (hidTotalAmt == '') {
                hidTotalAmt = '0';
            }
            if (ddlServices.value != '0' && ddlServices.options.length > 0) {
//                if (parseFloat(ActualValue) > parseFloat(hidTotalAmt)) {
//                    alert('Amount Can Not Greater Than ' + hidTotalAmt);
//                    document.getElementById(id).value = hidTotalAmt;
//                    ActualValue = hidTotalAmt;
//                }
                if (SelectedValue == '0') {
                    if (document.getElementById("hidServiceTaxability" + lastNo).value == '1') {
                        document.getElementById("txtTDSAmtCN" + lastNo).value = parseFloat(ActualValue).toFixed(2);
                        document.getElementById("txtDiscountCN" + lastNo).value = '';
                        document.getElementById("txtWriteOffCN" + lastNo).value = '';
                    }
                    else {
                        document.getElementById("txtDiscountCN" + lastNo).value = parseFloat(ActualValue).toFixed(2);
                        document.getElementById("txtTDSAmtCN" + lastNo).value = '';
                        document.getElementById("txtWriteOffCN" + lastNo).value = '';
                    }
                    document.getElementById("txtTotalAmtCN" + lastNo).value = parseFloat(ActualValue).toFixed(2);
                    CalculateTotalCreditNoteAmt();
                }
                else if (SelectedValue == '1') {
                    document.getElementById("txtSaleReturnSR" + lastNo).value = parseFloat(ActualValue).toFixed(2);
                    document.getElementById("txtTotalAmtSR" + lastNo).value = parseFloat(ActualValue).toFixed(2);
                    CalculateTotalSaleReturnAmt();
                }
                
            }
        }

        function ValidateCustomerDate(id) {
            var flag = true;
            if (document.getElementById("txtDate").value == '' || document.getElementById("txtDate").value == '__/__/____') {
                alert('Specify Transaction Date');
                flag = false;
                document.getElementById(id).selectedIndex = 0;
                document.getElementById("txtDate").focus();
            }
            if (flag == true) {
                setTimeout('__doPostBack(\'' + id + '\',\'\')', 0); 
            }
            return flag;
        }
        function ValidateParticular(id) {
            var flag = true;
            if (document.getElementById("txtDate").value == '' || document.getElementById("txtDate").value == '__/__/____') {
                alert('Specify Transaction Date');
                flag = false;                
                document.getElementById("txtDate").focus();
            }
            else if (document.getElementById("ddlCustomer").value == '0') {
                alert('Specify Customer');
                flag = false;
                document.getElementById("ddlCustomer").focus();
            }
            return flag;
        }
        function CalculateTdsCreditNoteAmt(id) {
            var lastNo = GetLastNumber(id.toString());
            var totalAmt = document.getElementById("txtTotalAmount" + lastNo).value;
            var tdsAmt = document.getElementById("txtTDSAmtCN" + lastNo).value;
            var discountAMT = document.getElementById("txtDiscountCN" + lastNo).value;
            var wirteOffAmt = document.getElementById("txtWriteOffCN" + lastNo).value;
            var totalCreditNote = document.getElementById("txtTotalAmtCN" + lastNo).value;
            if (totalAmt == '') {
                totalAmt = '0';
            }           
            if (tdsAmt == '') {
                tdsAmt = '0';
            }
            if (discountAMT == '') {
                discountAMT = '0';
            }
            if (wirteOffAmt == '') {
                wirteOffAmt = '0';
            }            
            var total = parseFloat(tdsAmt) + parseFloat(discountAMT) + parseFloat(wirteOffAmt);
            if (parseFloat(total)> parseFloat(totalAmt)) {
                alert('Credit Note amount should be  equal');
                if (document.getElementById("hidServiceTaxability" + lastNo).value == '1') {
                    document.getElementById("txtTDSAmtCN" + lastNo).value = parseFloat(totalAmt).toFixed(2);
                    document.getElementById("txtDiscountCN" + lastNo).value = '';
                    document.getElementById("txtWriteOffCN" + lastNo).value = '';
                }
                else {
                    document.getElementById("txtDiscountCN" + lastNo).value = parseFloat(totalAmt).toFixed(2);
                    document.getElementById("txtTDSAmtCN" + lastNo).value = '';
                    document.getElementById("txtWriteOffCN" + lastNo).value = '';
                }                
                document.getElementById("txtTotalAmtCN" + lastNo).value = parseFloat(totalAmt).toFixed(2);
            }
            else {
                document.getElementById("txtTotalAmtCN" + lastNo).value = parseFloat(total).toFixed(2);
            }
            CalculateTotalCreditNoteAmt();
        }
        function CalculateTotalCreditNoteAmt() {
            var count = document.getElementById("hidRowCountCN").value;
            var totalTaxableAmt = 0;
            var totalNonTaxableAmt = 0;
            var totalTaxableValue = 0;
            var totalServiceTaxAmt = 0;
            var totalPECessAmt = 0;
            var totalHECessAmt = 0;
            var totalTdsAmount = 0;
            var totalDiscountAmount = 0;
            var totalWriteOffAmount = 0;
            for (var i = 1; i <= count; i++) {
                var ChkDelete = document.getElementById("chkDelete" + i);
               
                    var ServiceTaxRate = document.getElementById("hidServiceTaxRate" + i).value;
                    var PECessRate = document.getElementById("hidPECessRate" + i).value;
                    var HECessRate = document.getElementById("hidHECessRate" + i).value;
                    var taxability = document.getElementById("hidServiceTaxability" + i).value;
                    var tdsAmt = document.getElementById("txtTDSAmtCN" + i).value;
                    var discountAMT = document.getElementById("txtDiscountCN" + i).value;
                    var wirteOffAmt = document.getElementById("txtWriteOffCN" + i).value;
                    var serviceTaxAmt = 0;
                   
                    if (ServiceTaxRate == '') {
                        ServiceTaxRate = 0;
                    }
                    if (PECessRate == '') {
                        PECessRate = 0;
                    }
                    if (HECessRate == '') {
                        HECessRate = 0;
                    }
                    if (tdsAmt == '') {
                        tdsAmt = 0;
                    }
                    if (discountAMT == '') {
                        discountAMT = 0;
                    }
                    if (wirteOffAmt == '') {
                        wirteOffAmt = 0;
                    }
                    totalTdsAmount += tdsAmt;
                    totalDiscountAmount += discountAMT;
                    totalWriteOffAmount += wirteOffAmt;
                    if (ChkDelete.checked != true) {
                    if (taxability == '1') {
                        var taxValue = parseFloat(discountAMT) + parseFloat(wirteOffAmt);
                        var taxDiff = 1 + ((((parseFloat(ServiceTaxRate) + (parseFloat(PECessRate) / 10) + (parseFloat(HECessRate) / 10)) * 100) / 1000) / 10);
                        var discount = parseFloat(discountAMT) / parseFloat(taxDiff);
                        var writeoff = parseFloat(wirteOffAmt) / parseFloat(taxDiff);
                        var taxable = parseFloat(discount) + parseFloat(writeoff);
                        totalTaxableAmt += parseFloat(tdsAmt) + parseFloat(taxable);
                        totalTaxableValue += parseFloat(taxable);
                        var tdsAmtWithoutST = parseFloat(tdsAmt) / parseFloat(taxDiff);
                        document.getElementById("hidTDSAmtWithoutSTCN" + i).value = parseFloat(tdsAmtWithoutST).toFixed(2);
                        serviceTaxAmt = parseFloat(tdsAmtWithoutST) * parseFloat(ServiceTaxRate) / 100;
                        document.getElementById("hidDiscountAmtCN" + i).value = parseFloat(discount).toFixed(2);
                        document.getElementById("hidWriteOffAmtCN" + i).value = parseFloat(writeoff).toFixed(2);
                    }
                    else if (taxability == '0') {
                        totalNonTaxableAmt += parseFloat(discountAMT) + parseFloat(wirteOffAmt);
                        document.getElementById("hidTDSAmtWithoutSTCN" + i).value = '0';
                    }
                    document.getElementById("hidServiceTaxAmtCN" + i).value = serviceTaxAmt.toFixed(2);
                    document.getElementById("hidPECessAmtCN" + i).value = parseFloat(parseFloat(serviceTaxAmt) * parseFloat(PECessRate) / 100).toFixed(2);
                    document.getElementById("hidHECessAmtCN" + i).value = parseFloat(parseFloat(serviceTaxAmt) * parseFloat(HECessRate) / 100).toFixed(2);
                }
            }
            totalServiceTaxAmt = parseFloat(totalTaxableValue) * parseFloat(ServiceTaxRate) / 100;
            totalPECessAmt = parseFloat(totalServiceTaxAmt) * parseFloat(PECessRate) / 100;
            totalHECessAmt = parseFloat(totalServiceTaxAmt) * parseFloat(HECessRate) / 100;
            document.getElementById("txtTaxableAmt").value = parseFloat(totalTaxableAmt).toFixed(2);
            document.getElementById("txtNonTaxableAmt").value = parseFloat(totalNonTaxableAmt).toFixed(2);
            document.getElementById("txtServiceTaxAmt").value = parseFloat(totalServiceTaxAmt).toFixed(2);
            document.getElementById("txtPECessAmt").value = parseFloat(totalPECessAmt).toFixed(2);
            document.getElementById("txtHECessAmt").value = parseFloat(totalHECessAmt).toFixed(2);
            document.getElementById("txtTotalAmount").value = parseFloat(totalTaxableAmt + totalNonTaxableAmt + totalServiceTaxAmt + totalPECessAmt + totalHECessAmt).toFixed(2);
            document.getElementById("hidTotalTdsAmount").value = parseFloat(totalTdsAmount).toFixed(2);
            document.getElementById("hidTotalWriteOffAmount").value = parseFloat(totalDiscountAmount).toFixed(2);
            document.getElementById("hidTotalDiscountAmount").value = parseFloat(totalWriteOffAmount).toFixed(2);           
            return true;
        }
        
        function CalculateTotalSaleReturnAmt() {
            var count = document.getElementById("hidRowCountSR").value;
            var totalTaxableAmt = 0;
            var totalNonTaxableAmt = 0;
            var totalTaxableValue = 0;
            var totalServiceTaxAmt = 0;
            var totalPECessAmt = 0;
            var totalHECessAmt = 0;
            var totalTdsAmount = 0;
            var totalDiscountAmount = 0;
            var totalWriteOffAmount = 0;
            for (var i = 1; i <= count; i++) {
                    var ChkDelete = document.getElementById("chkDelete" + i);
                    var ServiceTaxRate = document.getElementById("hidServiceTaxRate" + i).value;
                    var PECessRate = document.getElementById("hidPECessRate" + i).value;
                    var HECessRate = document.getElementById("hidHECessRate" + i).value;
                    var taxability = document.getElementById("hidServiceTaxability" + i).value;
                    var saleReturnAmt = document.getElementById("txtTotalAmount" + i).value;
                   
                    if (ServiceTaxRate == '') {
                        ServiceTaxRate = 0;
                    }
                    if (PECessRate == '') {
                        PECessRate = 0;
                    }
                    if (HECessRate == '') {
                        HECessRate = 0;
                    }
                    if (saleReturnAmt == '') {
                        saleReturnAmt = 0;
                    }
                    totalDiscountAmount += saleReturnAmt;
                    if (ChkDelete.checked != true) {
                    if (taxability == '1') {
                        var taxDiff = 1 + ((((parseFloat(ServiceTaxRate) + (parseFloat(PECessRate) / 10) + (parseFloat(HECessRate) / 10)) * 100) / 1000) / 10);
                        var taxable = parseFloat(saleReturnAmt) / parseFloat(taxDiff);
                        totalTaxableAmt += parseFloat(taxable);
                        totalTaxableValue += parseFloat(taxable);
                        //   alert("hidSaleReturnAmtSR Value=" + document.getElementById("hidSaleReturnAmtSR" + i).value);
                        document.getElementById("hidSaleReturnAmtSR" + i).value = parseFloat(taxable).toFixed(2);
                    }
                    else if (taxability == '0') {
                        totalNonTaxableAmt += parseFloat(saleReturnAmt);
                        //alert("hidSaleReturnAmtSR Value=" + document.getElementById("hidSaleReturnAmtSR" + i).value);
                        document.getElementById("hidSaleReturnAmtSR" + i).value = parseFloat(taxable).toFixed(2);
                    }
                }
            }
            totalServiceTaxAmt = parseFloat(totalTaxableValue) * parseFloat(ServiceTaxRate) / 100;
            totalPECessAmt = parseFloat(totalServiceTaxAmt) * parseFloat(PECessRate) / 100;
            totalHECessAmt = parseFloat(totalServiceTaxAmt) * parseFloat(HECessRate) / 100;
            document.getElementById("txtTaxableAmt").value = parseFloat(totalTaxableAmt).toFixed(2);
            document.getElementById("txtNonTaxableAmt").value = parseFloat(totalNonTaxableAmt).toFixed(2);
            document.getElementById("txtServiceTaxAmt").value = parseFloat(totalServiceTaxAmt).toFixed(2);
            document.getElementById("txtPECessAmt").value = parseFloat(totalPECessAmt).toFixed(2);
            document.getElementById("txtHECessAmt").value = parseFloat(totalHECessAmt).toFixed(2);
            document.getElementById("txtTotalAmount").value = parseFloat(totalTaxableAmt + totalNonTaxableAmt + totalServiceTaxAmt + totalPECessAmt + totalHECessAmt).toFixed(2);
            document.getElementById("hidTotalTdsAmount").value = parseFloat(totalTdsAmount).toFixed(2);
            document.getElementById("hidTotalWriteOffAmount").value = parseFloat(totalDiscountAmount).toFixed(2);
            document.getElementById("hidTotalDiscountAmount").value = parseFloat(totalWriteOffAmount).toFixed(2);  
            return true;
        }

        function ValidateBothTableAmt() {
            var count = document.getElementById("hidRowCountMain").value;
            var radioList = document.getElementById("rbtCreditNoteType");
            var Inputs = radioList.getElementsByTagName("input");
            var SelectedValue;
            var flag = true;
            for (var i = 0; i < Inputs.length; i++) {
                if (Inputs[i].type == "radio") {
                    if (Inputs[i].checked) {
                        SelectedValue = Inputs[i].value;
                        break;
                    }
                }
            }
            if (document.getElementById("ddlFormat").value == '0') {
                alert('Specify Credit Note Format');
                flag = false;
                document.getElementById("ddlFormat").focus();
            }
            else if (document.getElementById("ddlCustomer").value == '0') {
                alert('Specify Customer');
                flag = false;
                document.getElementById("ddlCustomer").focus();
            }
            else if (document.getElementById("txtDate").value == '' || document.getElementById("txtDate").value == '__/__/____') {
                alert('Specify Date');
                flag = false;
                document.getElementById("txtDate").focus();
            }
            else if (ValidateAddMoreMain() == false) {
                flag = false;
            }
            else {
                for (var i = 1; i <= count; i++) {
                    if (SelectedValue == '0') {
                        if (parseFloat(document.getElementById("txtTotalAmtCN" + i).value) != parseFloat(document.getElementById("txtTotalAmount" + i).value)) {
                            flag = false;
                            alert('Amount Receivable should be matched both tables');
                            document.getElementById("txtTotalAmtCN" + i).focus();
                            break;
                        }
                    }
                    else if (SelectedValue == '1') {
                        if (parseFloat(document.getElementById("txtTotalAmtSR" + i).value)!= parseFloat(document.getElementById("txtTotalAmount" + i).value)) {
                            flag = false;
                            alert('Amount Receivable should be matched both tables');
                            document.getElementById("txtTotalAmtSR" + i).focus();
                            break;
                        }
                    }
                }
            }
            return flag;
        }
        function NoServiceRepeat(id) {
            var flag = true;
            var ddl = document.getElementById(id);
            var currentvalue = ddl.options[ddl.selectedIndex].value;

            var strlength = ddl.id.toString().length;
            var index = parseInt(ddl.id.substring(11, strlength), strlength);
            var currentParticular = document.getElementById('ddlInvoiceParticular' + index.toString());
            var currentParticularValue = currentParticular.options[currentParticular.selectedIndex].value;

            var count = document.getElementById('hidRowCountMain').value;
            for (var i = 1; i <= count; i++) {

                var previousParticular = document.getElementById('ddlInvoiceParticular' + i.toString());
                var previousParticularValue = previousParticular.options[previousParticular.selectedIndex].value;

                var previous = document.getElementById('ddlServices' + i.toString());
                var previousvalue = previous.options[previous.selectedIndex].value;
                if (currentParticular != previousParticular) {
                    if (currentParticularValue == previousParticularValue && currentParticularValue != '0') {
                        if (ddl != previous) {
                            if (currentvalue == previousvalue && currentvalue != '0') {
                                alert('Please select unique service !');
                                ddl.selectedIndex = 0;
                                ddl.focus();
                                flag = false;
                                break;

                            }
                        }
                    }
                }
            }
            if (flag == true) {
                setTimeout('__doPostBack(\'' + id + '\',\'\')', 0);
            }
            return flag;
        }
        function checkAlLChecked() {
            var radioList = document.getElementById("rbtCreditNoteType");
            var Inputs = radioList.getElementsByTagName("input");
            var SelectedValue;
            for (var i = 0; i < Inputs.length; i++) {
                if (Inputs[i].type == "radio") {
                    if (Inputs[i].checked) {
                        SelectedValue = Inputs[i].value;
                        break;
                    }
                }
            }
            
            var Count = document.getElementById("hidRowCountMain").value;
            var j = 0;
            for (var i = 1; i <= Count; i++) {
                var checkbx = document.getElementById("chkDelete" + i.toString());
                if (checkbx.checked == true) {
                if (SelectedValue == '0') {
                    var checkbxCN = document.getElementById("chkDeleteCN" + i.toString());
                    if (checkbxCN != null) {
                        checkbxCN.checked = true;
                    }
                         }
                         else
                         {
                             var checkbxSR = document.getElementById("chkDeleteSR" + i.toString());
                             if (checkbxSR != null) {
                                 checkbxSR.checked = true;
                             }
                         }
                    j++;
                }
                if (checkbx.checked != true) {
                    if (SelectedValue == '0') {
                        var checkbxCN = document.getElementById("chkDeleteCN" + i.toString());
                        if (checkbxCN != null) {
                            checkbxCN.checked = false;
                        }
                    }
                    else {
                        var checkbxSR = document.getElementById("chkDeleteSR" + i.toString());
                        if (checkbxSR != null) {
                            checkbxSR.checked = false;
                        }
                    }
                }
                if (j == Count) {
                    alert("All record can't be deleted !");
                    checkbx.checked = false;
                    if (SelectedValue == '0') {
                        var checkbxCN = document.getElementById("chkDeleteCN" + i.toString());
                        if (checkbxCN != null) {
                            checkbxCN.checked = false;
                        }
                    }
                    else {
                        var checkbxSR = document.getElementById("chkDeleteSR" + i.toString());
                        if (checkbxSR != null) {
                            checkbxSR.checked = false;
                        }
                    }
                    break;
                }
            }
            document.getElementById("txtTotalAmount1").focus();
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
        <asp:HiddenField ID="hidTDSLid" runat="server" />
        <asp:HiddenField ID="hidWriteOffLid" runat="server" />
          <asp:HiddenField ID="hidRowCountSR" runat="server" Value="0" />
          <asp:HiddenField ID="hidCreditNoteID" runat="server" />
          <asp:HiddenField ID="hidVoudate" runat="server" />
          <asp:HiddenField ID="hidTranID" runat="server" />
          <asp:HiddenField ID="hidVouSerial" runat="server" />
          <asp:HiddenField ID="hidRefdetails" runat="server" />
          <asp:HiddenField ID="hidOldRbtCreditNoteOpt" runat="server" />
          
          <asp:HiddenField ID="hidOldTdsLid" runat="server" />
          <asp:HiddenField ID="hidOldWriteOff" runat="server" />
          <asp:HiddenField ID="hidSTLid" runat="server" />
          <asp:HiddenField ID="hidPELid" runat="server" />
          <asp:HiddenField ID="hidHELid" runat="server" />
          
          <table id="tblOldChildID" runat="server">
          <tr><td>
          <asp:HiddenField ID="hidOldChildIDCount" runat="server" Value="1" />
          <asp:HiddenField ID="hidOldChildID1" runat="server" Value="0" />
          <asp:HiddenField ID="hidRefID1" runat="server" Value="0" />
          </td></tr>
          </table>
        <div style="text-align:center">
            <asp:Label ID="lblMsg" runat="server"></asp:Label>
        </div>
        <table class="tablecontent" style="width:99%" cellpadding="2" cellspacing="0">
            <tr>
                <td colspan="4" class="headtd" align="center">
                    Credit Note
                </td>
            </tr>
            <tr>
                <td style="width:15%;">
                    Bill Format:<span style="color:Red;">*</span>
                </td>
                <td style="width:45%;">
                    <asp:DropDownList ID="ddlFormat" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlFormat_OnSelectedIndexChanged" CssClass="dropdown"></asp:DropDownList>
                </td>
                <td style="width:10%;">
                    Customer
                </td>
                <td style="width:30%;">
                    <asp:DropDownList ID="ddlCustomer" runat="server" CssClass="dropdown" onchange="return ValidateCustomerDate(this.id);" AutoPostBack="true" OnSelectedIndexChanged="ddlCustomer_OnSelectedIndexChanged"></asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>
                    Credit Note No.
                </td>
                <td>
                    <asp:TextBox ID="txtPrefix" runat="server" CssClass="input" Width="100px" Enabled="false"></asp:TextBox>
                    <asp:TextBox ID="txtCreditNoteNo" runat="server" CssClass="input" Width="100px" Enabled="false"></asp:TextBox>
                    <asp:TextBox ID="txtSuffix" runat="server" CssClass="input" Width="100px" Enabled="false"></asp:TextBox>
                </td>
                <td>
                    Ref. No.
                </td>
                <td>
                    <asp:TextBox ID="txtRefNo" runat="server" CssClass="input" ></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    Date
                </td>
                <td colspan="3">
                    <asp:TextBox ID="txtDate" runat="server" CssClass="input" OnTextChanged="txtDate_OnTextChanged" AutoPostBack="true"></asp:TextBox>
                    <asp:ImageButton ID="imgDate" runat="server" ImageUrl="~/Images/calendar.gif" />
                    <AjaxControl:CalendarExtender ID="calDate" runat="server" TargetControlID="txtDate" PopupButtonID="imgDate" Format="dd/MM/yyyy"></AjaxControl:CalendarExtender>
                    
                </td>                
            </tr>            
            <tr>
               <td colspan="4" style="border-top:solid 1px #818181; margin-top:5px; margin-bottom:5px;">
                    <asp:RadioButtonList ID="rbtCreditNoteType" runat="server" OnSelectedIndexChanged="rbtCreditNoteType_OnSelectedIndexChanged" AutoPostBack="true" RepeatDirection="Horizontal">
                        <asp:ListItem Text="Credit Note" Value="0" Selected="True"></asp:ListItem>
                        <asp:ListItem Text="Sale Return" Value="1"></asp:ListItem>
                    </asp:RadioButtonList>
                </td>
            </tr>
        </table>
        
    </div>
    <div style="width:99%;">
        <asp:HiddenField ID="hidRowCountMain" runat="server" Value="1" />
        <table id="tblCreditNoteMain" class="tablecontent" runat="server" width="100%"  cellpadding="2" cellspacing="0">
            <tr>
            <td class="headtd" style="border-right: 1px solid #818181; border-bottom: 1px solid #818181; text-align: center;
                    font-weight: bold; width: 5%; vertical-align: top" align="center">
                    Delete
                </td>
                <td class="headtd" style="width:22%; border-right:solid 1px #818181;" align="center">
                    Particulars
                </td>
                <td class="headtd" style="width:14%; border-right:solid 1px #818181;" align="center">
                    Services
                </td>
                <td class="headtd" style="width:14%; border-right:solid 1px #818181;" align="center">
                    Original Amt.
                </td>                
                <td class="headtd" style="width:15%; border-right:solid 1px #818181;" align="center">
                    Pending Amt.
                </td>
                <td class="headtd" style="width:15%; border-right:solid 1px #818181;" align="center">
                    Additional Desc.
                </td>
                <td class="headtd" style="width:15%;" align="center">
                    Amount
                </td>                
            </tr>
            <tr>
            <td style="width: 5%; vertical-align: top" align="center">
              <asp:CheckBox ID="chkDelete1" runat="server" Width="98%" onclick="checkAlLChecked();" />
              </td>
                <td>
                    <asp:DropDownList ID="ddlInvoiceParticular1" runat="server" CssClass="dropdown" Width="98%" AutoPostBack="true" onclick="return ValidateParticular(this.id);" OnSelectedIndexChanged="ddlParticular_OnSelectedIndexChanged"></asp:DropDownList>
                    <asp:HiddenField ID="hidServiceTaxRate1" runat="server" Value="0" />
                    <asp:HiddenField ID="hidPECessRate1" runat="server" Value="0" />
                    <asp:HiddenField ID="hidHECessRate1" runat="server" Value="0" />
                </td>
                <td>
                    <asp:DropDownList ID="ddlServices1" runat="server" CssClass="dropdown" Width="98%" AutoPostBack="true" onchange="return NoServiceRepeat(this.id);" OnSelectedIndexChanged="ddlServiecs_OnSelectedIndexChanged"></asp:DropDownList>
                    <asp:HiddenField ID="hidServiceTaxability1" runat="server" />
                </td>
                <td>
                    <asp:TextBox ID="txtOriginalAmt1" runat="server" CssClass="DisableInputNumber" onkeydown="return EnabledTabKey(this.id, event);" Width="98%"></asp:TextBox>
                </td>
                 <td>
                    <asp:TextBox ID="txtPendingAmt1" runat="server" CssClass="DisableInputNumber" onkeydown="return EnabledTabKey(this.id, event);" Width="98%"></asp:TextBox>
                </td>
                <td>
                    <asp:TextBox ID="txtAddDescription1" runat="server" CssClass="input" Width="98%"></asp:TextBox>
                </td>
                 <td>
                    <asp:TextBox ID="txtTotalAmount1" runat="server" CssClass="inputnumber" onkeypress="return isNumberKey(this.id,event);" onblur="return SetAmount(this.id);" Width="98%"></asp:TextBox>
                    <asp:HiddenField ID="hidTotalAmout1" runat="server" />
                </td>
            </tr>
        </table>
        <asp:Button ID="btnAddMore" runat="server" Text="Add More" CssClass="button" OnClientClick="return ValidateAddMoreMain();" OnClick="btnAddMore_CLick" /> &nbsp;
        <%--<asp:Button ID="btnDeleteRow" runat="server" Text="Delete" CssClass="button" OnClick="btnDeleteRow_Click" />--%>
    </div>
    <asp:Panel ID="panelCreditNote" runat="server" Width="99%">
        <asp:HiddenField ID="hidRowCountCN" runat="server" Value="0" />
        <table id="tblTdsCreditNote" runat="server" class="tablecontent" style="margin-top:45px;" width="100%">
            <tr>
                <td class="headtd" style="border-right:solid 1px #818181; width:5%;" align="center">
                   Delete
                </td>
                <td class="headtd" style="border-right:solid 1px #818181; width:18%;" align="center">
                    Particulers
                </td>
                 <td class="headtd" style="border-right:solid 1px #818181;  width:18%;" align="center">
                    Service
                </td>
                 <td class="headtd" style="border-right:solid 1px #818181;  width:14%;" align="center">
                    TDS Amt
                </td>
                 <td class="headtd" style="border-right:solid 1px #818181;  width:15%;" align="center">
                    Discount
                </td>
                 <td class="headtd" style="border-right:solid 1px #818181;  width:15%;" align="center">
                    Write Off
                </td>
                 <td class="headtd" style="width:15%;" align="center">
                    Total Amount
                </td>
            </tr>
        </table>        
    </asp:Panel>
    <asp:Panel ID="panelSalesReturn" runat="server" Visible="false" Width="99%">
  
        <table id="tblTDSSaleReturn" runat="server" class="tablecontent" style="margin-top:45px;" width="100%">
            <tr>
            <td class="headtd" style="border-right:solid 1px #818181; width:5%;" align="center">
                   Delete
               </td>
                <td class="headtd" style="border-right:solid 1px #818181; width:25%;" align="center">
                    Particulers
                </td>
                 <td class="headtd" style="border-right:solid 1px #818181;  width:25%;" align="center">
                    Service
                </td>
                 <td class="headtd" style="border-right:solid 1px #818181;  width:25%;" align="center">
                    Sales Return
                </td>
                 <td class="headtd" style="width:20%;" align="center">
                    Total Amount
                </td>                 
            </tr>
        </table>        
    </asp:Panel>
    <div style="width:99%; margin-top:15px;">
        <table width="100%" class="tablecontent">
            <tr>
                <td style="width: 50%; border-right:solid 1px #818181;" valign="top">
                    <table cellpadding="2" width="100%">
                        <tr>
                            <td style="width: 20%">
                                Narration
                            </td>
                            <td style="width: 80%">
                                <asp:TextBox ID="txtNarration" runat="server" CssClass="input" Width="95%"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Remarks
                            </td>
                            <td>
                                <asp:TextBox ID="txtRemarks" runat="server" CssClass="input" Width="95%"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Prepared By
                            </td>
                            <td>
                                <asp:TextBox ID="txtPreparedBy" runat="server" CssClass="input" Width="95%"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Checked By
                            </td>
                            <td>
                                <asp:TextBox ID="txtCheckedBy" runat="server" CssClass="input" Width="95%"></asp:TextBox>
                            </td>
                        </tr>
                    </table>
                </td>
                <td style="width: 50%;" valign="top">
                    <table cellpadding="2" style="width: 100%">
                        <tr>
                            <td colspan="2">
                                Taxable Amount
                            </td>
                            <td align="right">
                                <asp:TextBox ID="txtTaxableAmt" runat="server" CssClass="DisableInputNumber" Width="95%" onkeydown="return EnabledTabKey(this.id, event);"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                Non Taxable Amount
                            </td>
                            <td align="right">
                                <asp:TextBox ID="txtNonTaxableAmt" runat="server" CssClass="DisableInputNumber" Width="95%"  onkeydown="return EnabledTabKey(this.id, event);"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td style="width: 30%">
                                Service Tax
                                <asp:HiddenField ID="hidServiceTaxLid" runat="server" Value="0" />
                                <asp:HiddenField ID="hidServiceTaxRateCurrent" runat="server" Value="0" />
                            </td>
                            <td style="widows: 20%" align="right">
                                <asp:TextBox ID="txtServiceTaxPer" runat="server" Width="80px" CssClass="DisableInputNumber" onkeydown="return EnabledTabKey(this.id, event);"></asp:TextBox>
                            </td>
                            <td style="width: 50%" align="right">
                                <asp:TextBox ID="txtServiceTaxAmt" runat="server" CssClass="DisableInputNumber" Width="95%" onkeydown="return EnabledTabKey(this.id, event);"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                P.E.Cess
                                <asp:HiddenField ID="hidPECessLid" runat="server" Value="0" />
                                <asp:HiddenField ID="hidPECessRateCurrent" runat="server" Value="0" />
                            </td>
                            <td align="right">
                                <asp:TextBox ID="txtPECessPer" runat="server" Width="80px" CssClass="DisableInputNumber" onkeydown="return EnabledTabKey(this.id, event);"></asp:TextBox>
                            </td>
                            <td align="right">
                                <asp:TextBox ID="txtPECessAmt" runat="server" CssClass="DisableInputNumber" Width="95%" onkeydown="return EnabledTabKey(this.id, event);"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                H.E.Cess
                                <asp:HiddenField ID="hidHECessLid" runat="server" Value="0" />
                                <asp:HiddenField ID="hidHECessRateCurrent" runat="server" Value="0" />
                            </td>
                            <td align="right">
                                <asp:TextBox ID="txtHECessPer" runat="server" Width="80px" CssClass="DisableInputNumber" onkeydown="return EnabledTabKey(this.id, event);"></asp:TextBox>
                            </td>
                            <td align="right">
                                <asp:TextBox ID="txtHECessAmt" runat="server" CssClass="DisableInputNumber" Width="95%" onkeydown="return EnabledTabKey(this.id, event);"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Total Amount
                            </td>
                            <td align="right">
                                <asp:HiddenField ID="hidTotalTdsAmount" runat="server" Value="0" />
                                <asp:HiddenField ID="hidTotalWriteOffAmount" runat="server" Value="0" />
                                <asp:HiddenField ID="hidTotalDiscountAmount" runat="server" Value="0" />
                                <asp:HiddenField ID="hidTotalAdditionalAmount" runat="server" Value="0" />
                            </td>
                            <td align="right">
                                <asp:TextBox ID="txtTotalAmount" runat="server" CssClass="DisableInputNumber" Width="95%" onkeydown="return EnabledTabKey(this.id, event);"></asp:TextBox>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table> 
    </div>
    <div style="width:100%; text-align:center;">
        <asp:Button ID="btnSave" runat="server" Text="Save" CssClass="button" OnClientClick="return ValidateBothTableAmt();" OnClick="btnSave_Click" />
        <asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClick="btnCancel_Click" CssClass="button" />  
    </div>    
    <asp:GridView ID="display" runat="server">
    </asp:GridView>
    <asp:GridView ID="GridView1" runat="server">
    </asp:GridView>
      <asp:GridView ID="GridView2" runat="server">
    </asp:GridView>
    </form>
</body>
</html>
